//
//  RootViewController.m
//  QKSeekool
//
//  Created by 趣看 on 14/10/28.
//  Copyright (c) 2014年 趣看科技有限责任公司. All rights reserved.
//

#import "RootViewController.h"
#import "SKRootCellTableViewCell.h"
#import "UIColor+Hex.h"
#import "JDSideMenu.h"
#import "MianViewController.h"
#import "YearViewController.h"
#import "MonthViewController.h"
#import "WeekViewController.h"
#import "ShopViewController.h"
#import "HTMLViewController.h"
#import "UserPhotoView.h"

@interface RootViewController ()
{
    //保存列表的名字
    NSArray *listName;
    //保存图片的名字
    NSArray *listpicture;
    //保存上一次点击cell时的序列，用于判断是否需要重新创建控制器
    int controller_order;
    
}
@end

@implementation RootViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    
    
    //初始化为0，表示默认是主界面
    controller_order = 0;
    
    //加载表视图
    [self createTableView];
    
    [self.view setBackgroundColor:[UIColor blackColor]];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -

#pragma mark - 创建表视图
- (void)createTableView
{
    UserPhotoView *photoView = [[UserPhotoView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
    [photoView initSubview];
    
    [self.view addSubview:photoView];
    
    slider_table = [[UITableView alloc] init];
    
    listName = @[@"待办事项",@"周视图",@"月视图",@"年视图",@"日程商店",@"登入网页版"];
    
    listpicture = @[@"todoButton",@"weekButton",@"monthBtton",@"yearButton",@"storeButton",@"storeButton"];
    
  
    //4寸
    [slider_table setFrame:CGRectMake(-20, 150, self.view.bounds.size.width, self.view.bounds.size.height - 150)];
   
    
    slider_table.delegate = self;
    
    slider_table.dataSource = self;
    
    [self.view addSubview:slider_table];
    
    slider_table.backgroundColor = [UIColor clearColor];
    
    [slider_table setSeparatorColor:[UIColor clearColor]];
    //[tableView setSeparatorColor:[UIColor colorWithHexString:@"3B424C" ]];
    
}


#pragma mark - 添加tableview的内容
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseIdetify = @"SKRootCell";
    
    SKRootCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdetify];
    
    if (!cell)
    {
        cell = [[SKRootCellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdetify];
        
    }
    
    if (indexPath.row == 5)
    {
        UILabel *topLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 370/6-4, 340, 2)];
        [topLine setBackgroundColor:[UIColor colorWithHexString:@"3B424C"]];
        
        UILabel *bottomLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 370/6-2, 340, 2)];
        [bottomLine setBackgroundColor:[UIColor colorWithHexString:@"20242B"]];
        
        [cell addSubview:topLine];
        [cell addSubview:bottomLine];
    }
    
    
    cell.backgroundColor = [UIColor clearColor];
    
    NSString *cellName    = nil;
    NSString *cellPicture = nil;
    
    
    cellName = listName[indexPath.row];
    
    cellPicture = listpicture[indexPath.row];
    
    
    
    cell.labelView.text = cellName;
    
    cell.iconView.image = [UIImage imageNamed:cellPicture];
    
    return cell;
}

#pragma mark - cell 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int index = (int) indexPath.row;
    
    if(controller_order == index)
    {
        
         [[JDSideMenu sharedSideMenu] hideMenuAnimated:YES];
    
        
    }else
    {
        switch (index) {
                
            case 0:
            {
                MianViewController *mainController = [[MianViewController alloc] init];
               
                [[JDSideMenu sharedSideMenu] setContentController:mainController animted:YES];
                
               
                break;
            }
            case 1:
            {
                
                WeekViewController *mainController = [[WeekViewController alloc] init];
                
                [[JDSideMenu sharedSideMenu] setContentController:mainController animted:YES];
                break;
            }
            case 2:
            {
                MonthViewController *mainController = [[MonthViewController alloc] init];
                
                [[JDSideMenu sharedSideMenu] setContentController:mainController animted:YES];
                break;
            }
            case 3:
            {
                YearViewController *mainController = [[YearViewController alloc] init];
                
                [[JDSideMenu sharedSideMenu] setContentController:mainController animted:YES];
                break;
            }
            case 4:
            {
                ShopViewController *mainController = [[ShopViewController alloc] init];
                
                [[JDSideMenu sharedSideMenu] setContentController:mainController animted:YES];
                
                break;
            }
            case 5:
            {
                HTMLViewController *mainController = [[HTMLViewController alloc] init];
                
                [[JDSideMenu sharedSideMenu] setContentController:mainController animted:YES];
                
                break;
            }
            case 6:
            {
                break;
            }
                
                
            default:
                break;
        }
        
 
         controller_order = index;
    }
    
    
    
}
#pragma  mark - cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 370/6;
}


@end
